﻿/*
* Copyright (c) 2008 michiyasu wada
* http://www.seyself.com/
* 
* Distributed under The MIT License.
* [http://www.opensource.org/licenses/mit-license.php]
*/

//****************************************************************************
// ActionScript Standard Library
// flash.geom.ColorTransform object
//****************************************************************************

class flash7.geom.ColorTransform
{
    public var redMultiplier:Number   = 1.0;
    public var greenMultiplier:Number = 1.0;
    public var blueMultiplier:Number  = 1.0;
    public var alphaMultiplier:Number = 1.0;
    public var redOffset:Number       = 0;
    public var greenOffset:Number     = 0;
    public var blueOffset:Number      = 0;
    public var alphaOffset:Number     = 0;
    
    public function get rgb():Number
    {
        return ( redOffset << 16 ) + ( greenOffset << 8 ) + blueOffset;
    }
    public function set rgb( value:Number ):Void
    {
        redMultiplier   = 0;
        greenMultiplier = 0;
        blueMultiplier  = 0;
        redOffset   = value >> 16 & 0xFF;
        greenOffset = value >> 8  & 0xFF;
        blueOffset  = value       & 0xFF;
    }
    
    public function ColorTransform( redMultiplier:Number, greenMultiplier:Number, 
                                    blueMultiplier:Number, alphaMultiplier:Number, 
                                    redOffset:Number, greenOffset:Number, 
                                    blueOffset:Number, alphaOffset:Number )
    {
        this.redMultiplier   = ( isNaN( redMultiplier ) )   ? 1.0 : redMultiplier;
        this.greenMultiplier = ( isNaN( greenMultiplier ) ) ? 1.0 : greenMultiplier;
        this.blueMultiplier  = ( isNaN( blueMultiplier ) )  ? 1.0 : blueMultiplier;
        this.alphaMultiplier = ( isNaN( alphaMultiplier ) ) ? 1.0 : alphaMultiplier;
        this.redOffset       = ( isNaN( redOffset ) )       ? 0   : redOffset;
        this.greenOffset     = ( isNaN( greenOffset ) )     ? 0   : greenOffset;
        this.blueOffset      = ( isNaN( blueOffset ) )      ? 0   : blueOffset;
        this.alphaOffset     = ( isNaN( alphaOffset ) )     ? 0   : alphaOffset;
    }
    
    public function concat ( second:ColorTransform ):Void
    {
        redMultiplier   *= second.redMultiplier;
        greenMultiplier *= second.greenMultiplier;
        blueMultiplier  *= second.blueMultiplier;
        alphaMultiplier *= second.alphaMultiplier;
        redOffset       += second.redOffset;
        greenOffset     += second.greenOffset;
        blueOffset      += second.blueOffset;
        alphaOffset     += second.alphaOffset;
    }
    
    public function toString():String
    {
        return "(redMultiplier=" + redMultiplier +
                ", greenMultiplier=" + greenMultiplier +
                ", blueMultiplier=" + blueMultiplier +
                ", alphaMultiplier=" + alphaMultiplier +
                ", redOffset=" + redOffset +
                ", greenOffset=" + greenOffset +
                ", blueOffset=" + blueOffset +
                ", alphaOffset="+ alphaOffset +")";
    }
    
}